from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-19 14:02:14.946002
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 19, Feb, 2022
Time: 14:02:21
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.1783
Nobs: 572.000 HQIC: -48.5957
Log likelihood: 6760.01 FPE: 6.01523e-22
AIC: -48.8626 Det(Omega_mle): 5.14647e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.346890 0.068540 5.061 0.000
L1.Burgenland 0.106392 0.041646 2.555 0.011
L1.Kärnten -0.110780 0.021685 -5.109 0.000
L1.Niederösterreich 0.188468 0.086843 2.170 0.030
L1.Oberösterreich 0.133289 0.085900 1.552 0.121
L1.Salzburg 0.254856 0.044081 5.782 0.000
L1.Steiermark 0.036603 0.058190 0.629 0.529
L1.Tirol 0.100107 0.046946 2.132 0.033
L1.Vorarlberg -0.069340 0.041405 -1.675 0.094
L1.Wien 0.020361 0.076340 0.267 0.790
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.053040 0.147903 0.359 0.720
L1.Burgenland -0.038027 0.089868 -0.423 0.672
L1.Kärnten 0.041375 0.046793 0.884 0.377
L1.Niederösterreich -0.204644 0.187399 -1.092 0.275
L1.Oberösterreich 0.461239 0.185364 2.488 0.013
L1.Salzburg 0.282209 0.095122 2.967 0.003
L1.Steiermark 0.113493 0.125568 0.904 0.366
L1.Tirol 0.304601 0.101305 3.007 0.003
L1.Vorarlberg 0.025387 0.089349 0.284 0.776
L1.Wien -0.029217 0.164734 -0.177 0.859
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199900 0.034996 5.712 0.000
L1.Burgenland 0.088889 0.021264 4.180 0.000
L1.Kärnten -0.007430 0.011072 -0.671 0.502
L1.Niederösterreich 0.239026 0.044341 5.391 0.000
L1.Oberösterreich 0.162245 0.043859 3.699 0.000
L1.Salzburg 0.039794 0.022507 1.768 0.077
L1.Steiermark 0.026555 0.029711 0.894 0.371
L1.Tirol 0.082001 0.023970 3.421 0.001
L1.Vorarlberg 0.053607 0.021141 2.536 0.011
L1.Wien 0.117495 0.038978 3.014 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.120955 0.034942 3.462 0.001
L1.Burgenland 0.043485 0.021232 2.048 0.041
L1.Kärnten -0.013077 0.011055 -1.183 0.237
L1.Niederösterreich 0.168699 0.044273 3.810 0.000
L1.Oberösterreich 0.337459 0.043793 7.706 0.000
L1.Salzburg 0.100556 0.022473 4.475 0.000
L1.Steiermark 0.110596 0.029666 3.728 0.000
L1.Tirol 0.090393 0.023934 3.777 0.000
L1.Vorarlberg 0.060912 0.021109 2.886 0.004
L1.Wien -0.020221 0.038919 -0.520 0.603
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.122186 0.065844 1.856 0.063
L1.Burgenland -0.046266 0.040008 -1.156 0.248
L1.Kärnten -0.045239 0.020831 -2.172 0.030
L1.Niederösterreich 0.135068 0.083427 1.619 0.105
L1.Oberösterreich 0.166446 0.082521 2.017 0.044
L1.Salzburg 0.284382 0.042347 6.716 0.000
L1.Steiermark 0.057595 0.055901 1.030 0.303
L1.Tirol 0.156168 0.045099 3.463 0.001
L1.Vorarlberg 0.097259 0.039777 2.445 0.014
L1.Wien 0.075245 0.073337 1.026 0.305
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.081021 0.051331 1.578 0.114
L1.Burgenland 0.025835 0.031190 0.828 0.407
L1.Kärnten 0.053449 0.016240 3.291 0.001
L1.Niederösterreich 0.189082 0.065039 2.907 0.004
L1.Oberösterreich 0.329986 0.064332 5.129 0.000
L1.Salzburg 0.034530 0.033013 1.046 0.296
L1.Steiermark 0.005643 0.043580 0.129 0.897
L1.Tirol 0.120361 0.035159 3.423 0.001
L1.Vorarlberg 0.066047 0.031010 2.130 0.033
L1.Wien 0.095880 0.057173 1.677 0.094
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169313 0.062099 2.727 0.006
L1.Burgenland 0.005114 0.037732 0.136 0.892
L1.Kärnten -0.065734 0.019647 -3.346 0.001
L1.Niederösterreich -0.109731 0.078681 -1.395 0.163
L1.Oberösterreich 0.211182 0.077827 2.713 0.007
L1.Salzburg 0.054731 0.039938 1.370 0.171
L1.Steiermark 0.248815 0.052721 4.719 0.000
L1.Tirol 0.499739 0.042534 11.749 0.000
L1.Vorarlberg 0.065523 0.037514 1.747 0.081
L1.Wien -0.075953 0.069166 -1.098 0.272
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160597 0.068834 2.333 0.020
L1.Burgenland -0.003190 0.041824 -0.076 0.939
L1.Kärnten 0.062813 0.021777 2.884 0.004
L1.Niederösterreich 0.166121 0.087215 1.905 0.057
L1.Oberösterreich -0.053810 0.086268 -0.624 0.533
L1.Salzburg 0.207794 0.044270 4.694 0.000
L1.Steiermark 0.138860 0.058439 2.376 0.017
L1.Tirol 0.055933 0.047147 1.186 0.235
L1.Vorarlberg 0.146746 0.041583 3.529 0.000
L1.Wien 0.121214 0.076667 1.581 0.114
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.394296 0.040349 9.772 0.000
L1.Burgenland -0.003119 0.024517 -0.127 0.899
L1.Kärnten -0.021405 0.012766 -1.677 0.094
L1.Niederösterreich 0.200753 0.051124 3.927 0.000
L1.Oberösterreich 0.229614 0.050569 4.541 0.000
L1.Salzburg 0.037327 0.025950 1.438 0.150
L1.Steiermark -0.017308 0.034256 -0.505 0.613
L1.Tirol 0.091101 0.027637 3.296 0.001
L1.Vorarlberg 0.050724 0.024375 2.081 0.037
L1.Wien 0.041101 0.044941 0.915 0.360
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036294 0.102080 0.169275 0.136381 0.095582 0.081705 0.032485 0.210468
Kärnten 0.036294 1.000000 -0.027837 0.132352 0.048216 0.085482 0.443604 -0.067260 0.089188
Niederösterreich 0.102080 -0.027837 1.000000 0.309717 0.118821 0.269290 0.065328 0.151622 0.287117
Oberösterreich 0.169275 0.132352 0.309717 1.000000 0.214619 0.293558 0.167864 0.136094 0.234087
Salzburg 0.136381 0.048216 0.118821 0.214619 1.000000 0.124041 0.091170 0.104717 0.124035
Steiermark 0.095582 0.085482 0.269290 0.293558 0.124041 1.000000 0.134706 0.106299 0.031792
Tirol 0.081705 0.443604 0.065328 0.167864 0.091170 0.134706 1.000000 0.063913 0.151967
Vorarlberg 0.032485 -0.067260 0.151622 0.136094 0.104717 0.106299 0.063913 1.000000 -0.005283
Wien 0.210468 0.089188 0.287117 0.234087 0.124035 0.031792 0.151967 -0.005283 1.000000